<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Solve a floor planning problem given graphs H &amp; V</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/cvxbook/Ch08_geometric_probs/html/floor_plan_graphs.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Solve a floor planning problem given graphs H &amp; V</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
Text output
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Section 8.8.1/2, Example 8.7, Boyd &amp; Vandenberghe "Convex Optimization"</span>
<span class="comment">% Joelle Skaf - 11/13/05</span>
<span class="comment">% (a figure is generated)</span>
<span class="comment">%</span>
<span class="comment">% Rectangles aligned with the axes need to be place in the smallest</span>
<span class="comment">% possible bounding box. No overlap is allowed. Each rectangle to be placed</span>
<span class="comment">% can be reconfigured, within some limits.</span>
<span class="comment">% In the current problem, 5 rectangles are to be place. We are given 2</span>
<span class="comment">% acyclic graphs H and V (for horizontal and vertical) that specify the</span>
<span class="comment">% relative positioning constraints of those rectangles.</span>
<span class="comment">% We are also given minimal areas for the rectangles.</span>

<span class="comment">% Input data</span>
n = 5;
<span class="comment">% for each entry i, X_tree(i) = parent(i)</span>
H_tree = [0 0 1 0 0;<span class="keyword">...</span>
          0 0 1 0 0;<span class="keyword">...</span>
          0 0 0 0 1;<span class="keyword">...</span>
          0 0 0 0 1;<span class="keyword">...</span>
          0 0 0 0 0];
V_tree = [0 0 0 1 0;<span class="keyword">...</span>
          1 0 0 0 0;<span class="keyword">...</span>
          0 0 0 1 0;<span class="keyword">...</span>
          0 0 0 0 0;<span class="keyword">...</span>
          0 0 0 0 0];

Amin = [100 100 100 100 100; <span class="keyword">...</span>
         20  50  80 150 200; <span class="keyword">...</span>
        180  80  80  80  80; <span class="keyword">...</span>
         20 150  20 200 110];
rho = 1;          <span class="comment">% minimum spacing constraints</span>

<span class="comment">% solving the problem by calling the general FLOORPLAN routine</span>
<span class="keyword">for</span> iter = 1:4
    A = Amin(iter,:);
    [W, H, w, h, x, y] = floorplan(H_tree, V_tree, rho, A, 1/5*ones(n,1), 5*ones(n,1));
    <span class="comment">% Plotting</span>
    subplot(2,2,iter)
    <span class="keyword">for</span> i=1:n
        fill([x(i); x(i)+w(i); x(i)+w(i); x(i)],[y(i);y(i);y(i)+h(i);y(i)+h(i)],0.90*[1 1 1]);
        hold <span class="string">on</span>;
        text(x(i)+w(i)/2, y(i)+h(i)/2,[<span class="string">'B'</span>,int2str(i)]);
    <span class="keyword">end</span>
    axis([0 W 0 H]);
    axis <span class="string">equal</span>; axis <span class="string">off</span>;
<span class="keyword">end</span>
</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="floor_plan_graphs__01.png" alt=""> 
</div>
</div>
</body>
</html>